<?php

namespace App\Admin\Controllers\Api;

use App\Models\User;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Nesk\Puphpeteer\Puppeteer;
use Illuminate\Support\Facades\Http;

class WeixinController extends Controller
{
	public function company(Request $request)
	{
		//$keyword=$request->keyword;

		$keyword = $request->input('q');

		
		
		$user_agent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko)";

		$queryUrl = "https://mp.weixin.qq.com/cgi-bin/searchbiz?action=search_biz&begin=0&count=5&query=".$keyword."&token=1915846676&lang=zh_CN&f=json&ajax=1";


		$cookie = "appmsglist_action_3975454104=card; ua_id=L5dHsJWxbejJaCUkAAAAAE_ol4Gw8EnMqqah9usqddE=; wxuin=22579264596721; mm_lang=zh_CN; RK=qeuFu4Gjaz; ptcz=7e7fb728c92a7bd10c8714b2f69624cb8e26bc1726c204dcad7bd136cec9e119; pgv_pvid=4215038740; rand_info=CAESIILpIoFjvBPmQvDhlZDA8hf5TA9ykstF5Bk/NRi71FQp; slave_bizuin=3975454104; data_bizuin=3975454104; bizuin=3975454104; data_ticket=riqFONlvwITPVdZOjPm/VgXt/5srzVwwS8bfF/+WyzdHMrn91YUx4BgSwiVY7NLo; slave_sid=MkxYdlgyRTRCdFB0V18xVTFtWlYwQll6R3lNZmNSTVVrS1pFWkFJN2NZREhxbzVkcjQyc2RzdGFBc0w3QmZUcWx2NV95RmNWY29jdVVuVzRyaWRHZHZqcVJsN3lHRHk5RjdnX0N1WFhzQTk2ckJJakx0Tk80MmhTWGVCMU0zeUFHUm9KWnV5Z2xnZzV4S2ZO; slave_user=gh_6d7bbc3c44f2; xid=e22837d40a0aa79ad54c6db6d0d77aa7; _clck=3975454104|1|fu1|0; _clsk=1shd02a|1741435246198|3|1|mp.weixin.qq.com/weheat-agent/payload/record";

		$response = Http::withHeaders(['cookie' => $cookie,'user_agent'=>$user_agent])
                ->get($queryUrl);
		if ($response->successful()) {
			$dds = $response->json();

			$res = [];
			if($dds['base_resp']['err_msg']=="ok"){

				foreach($dds['list'] as $k=>$v){

					$res[$k]['id'] = $v['fakeid'];
					$res[$k]['text']=$v['nickname'];
				}

				$result['data'] = $res;
				return $result;
			}
		}

		//dd(123);



	}

	public function wutou($url){

		ini_set('user_agent','Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727;)');

    	$puppeteer = new Puppeteer; // 新建 Puppeteer 实例

         $browser = $puppeteer->launch(['args'=>['--no-sandbox']]); // 启动无头浏览器
         $page = $browser->newPage(); // 打开新的标签页
       
         $page->tryCatch->goto($url,[
             'timeout' => 0,
             'read_timeout' => 30

         ]); // 访问页面
        	
       	 
         $html = $page->content();

         dd($html);
	}

	public function curl($url){
		$curl = curl_init();
		$cookie = "appmsglist_action_3975454104=card; ua_id=BulSpRyLwIVHcjFFAAAAAAuFm4jxetQoRq-qOxqK6oQ=; wxuin=18503783010187; mm_lang=zh_CN; pgv_pvid=3760479382; _clck=la1z9j|1|ftx|0; rewardsn=; wxtokenkey=777; xid=a0fa20eb5d4cbd1cd887e15a73d4282d; uuid=37aa82f354cf8d2828f214a2bd6bbbff; cert=U51oFmYhmppm4sdDra9pnE9evkYQgw0a; _qpsvr_localtk=0.9371174860705715; data_bizuin=3975454104; bizuin=3975454104; master_user=gh_6d7bbc3c44f2; master_sid=X3FLUjBJVUp0UE5GTU9WanplX0xfdmNXRHgyYW1lSGFQVXlrTkp1eElBZXZ3VkE4bVlscXhNeWFoa2hWRVg0eVl0SmhfOURCa1B6cjU2bXJQX1FtR3UzdmgwdG96Umk3UmV4ZUZLYXJOYlJDS09rdlFWTW5qbTR5WmJsUXRmN0JXdXpLeURJRTFKM3I5OXRz; master_ticket=b6b8eac216d68e8aa329de97963195a9; data_ticket=RsLGjNp7WtRPhsYf5XHe+wRsHsbJ+bTTZJO83sbZYwK4aPPSo+COGvdLyXp6Pf5T; rand_info=CAESIDhC4YG49w0XqhSgPUEEvshTLsNF4IMLexR2EB8RJuw1; slave_bizuin=3975454104; slave_user=gh_6d7bbc3c44f2; slave_sid=QU9BVV9tUEV6WjBOY3g5R1FmM1Q5SWFqNFV3MWpGdUttclBxRXI2dXRCcTRhcmdLTTU5UTZxTVBpOXFVZ05ya3ZKbW9KeV91QWx2aENWUnRpQjJrRDJlNkVpY0hMNGFrTlpKTlNVV3p5R040Z0hWcUlhdUdHdGFaM1JndWJkVERDbmpxVUw5WFZPblJJUmFU; _clsk=ql5jyi|1741061875736|5|1|mp.weixin.qq.com/weheat-agent/payload/record";

		curl_setopt_array($curl, array(
		   CURLOPT_URL => $url,
		   CURLOPT_RETURNTRANSFER => true,
		   CURLOPT_ENCODING => '',
		   CURLOPT_MAXREDIRS => 10,
		   CURLOPT_TIMEOUT => 0,
		   CURLOPT_FOLLOWLOCATION => true,
		   CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
		   CURLOPT_SSL_VERIFYPEER => false,
		   CURLOPT_CUSTOMREQUEST => 'get',
		   CURLOPT_HTTPHEADER => array(
 "authority: mp.weixin.qq.com",
"accept: */*",
"accept-language: zh-CN,zh;q=0.9" ,
"cookie: appmsglist_action_3975454104=card; ua_id=BulSpRyLwIVHcjFFAAAAAAuFm4jxetQoRq-qOxqK6oQ=; wxuin=18503783010187; mm_lang=zh_CN; pgv_pvid=3760479382; _clck=la1z9j^|1^|ftx^|0; rewardsn=; wxtokenkey=777; xid=a0fa20eb5d4cbd1cd887e15a73d4282d; uuid=37aa82f354cf8d2828f214a2bd6bbbff; cert=U51oFmYhmppm4sdDra9pnE9evkYQgw0a; _qpsvr_localtk=0.9371174860705715; data_bizuin=3975454104; bizuin=3975454104; master_user=gh_6d7bbc3c44f2; master_sid=X3FLUjBJVUp0UE5GTU9WanplX0xfdmNXRHgyYW1lSGFQVXlrTkp1eElBZXZ3VkE4bVlscXhNeWFoa2hWRVg0eVl0SmhfOURCa1B6cjU2bXJQX1FtR3UzdmgwdG96Umk3UmV4ZUZLYXJOYlJDS09rdlFWTW5qbTR5WmJsUXRmN0JXdXpLeURJRTFKM3I5OXRz; master_ticket=b6b8eac216d68e8aa329de97963195a9; data_ticket=RsLGjNp7WtRPhsYf5XHe+wRsHsbJ+bTTZJO83sbZYwK4aPPSo+COGvdLyXp6Pf5T; rand_info=CAESIDhC4YG49w0XqhSgPUEEvshTLsNF4IMLexR2EB8RJuw1; slave_bizuin=3975454104; slave_user=gh_6d7bbc3c44f2; slave_sid=QU9BVV9tUEV6WjBOY3g5R1FmM1Q5SWFqNFV3MWpGdUttclBxRXI2dXRCcTRhcmdLTTU5UTZxTVBpOXFVZ05ya3ZKbW9KeV91QWx2aENWUnRpQjJrRDJlNkVpY0hMNGFrTlpKTlNVV3p5R040Z0hWcUlhdUdHdGFaM1JndWJkVERDbmpxVUw5WFZPblJJUmFU; _clsk=js9zg1^|1741074992794^|1^|1^|mp.weixin.qq.com/weheat-agent/payload/record",
"referer: https://mp.weixin.qq.com/cgi-bin/appmsg?t=media/appmsg_edit_v2&action=edit&isNew=1&type=10&token=642733171&lang=zh_CN&timestamp=1741061874493",
'sec-ch-ua: Chromium";v="112", "Google Chrome";v="112", "Not:A-Brand";v="99"',
"sec-ch-ua-mobile: ?0",
'sec-ch-ua-platform: ^\^"Windows^\^"',
"sec-fetch-dest: empty",
"sec-fetch-mode: cors",
		   	 "sec-fetch-site: same-origin",
		      'user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36"',
		      'x-requested-with:XMLHttpRequest'
		      
		   ),
		));

	   $response = curl_exec($curl);

	   //dd($url);
	   return $response;
	}




}
